package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.app.DownLoadUserReviewDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserReviewDataCommand;
import com.cskaoyan.wordmemorize.service.UserReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/review")
public class UserReviewController {
    @Autowired
    UserReviewService userReviewService;

    @PostMapping("voc")
    public Result addUserRovRev(@RequestBody List<Long> vocId) {
        long userId = StpKit.USER.getLoginIdAsLong();
        userReviewService.addUserRovRev(vocId, userId);
        return Result.ok();
    }

    @GetMapping("data")
    public Result<DownLoadUserReviewDTO> downloadUserReviewData(PageRequest pageRequest) {
        long userId = StpKit.USER.getLoginIdAsLong();
        DownLoadUserReviewDTO downLoadUserReviewDTO = userReviewService.downloadUserReviewData(pageRequest, userId);
        return Result.ok(downLoadUserReviewDTO);
    }

    @PostMapping("data")
    public Result synchronizeUserReviewData(@RequestBody UserReviewDataCommand userReviewDataCommand) {
        long userId = StpKit.USER.getLoginIdAsLong();
        userReviewService.synchronizeUserReviewData(userReviewDataCommand, userId);
        return Result.ok();
    }
}
